package view.Items;

import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;

import view.Tabs.CharacterGUI;
import view.Tabs.HomePageGUI;

import commons.Entities.LegenCharacterThin;

import controller.ControllerFunctions;

public class TopCharactersListGUI {

	protected CharacterGUI charGUIPage;
	protected Font fHeadFont;
	protected Font fLabelFont;
	protected Font fButtonFont;

	public TopCharactersListGUI(String listHeader, List<LegenCharacterThin> lctList, int x, int y, Composite gr, final Display mainDisp, final CTabFolder ctfHome) {

		initFonts(mainDisp);

		final Color clrWhite = new Color(mainDisp, 255, 255, 255);

		// the table group
		Group grTable = new Group(gr, SWT.BORDER_DASH);
		grTable.setBounds(x, y, 250, 450);
		Label lblListHeader = new Label(grTable, SWT.CENTER | SWT.UNDERLINE_DOUBLE);
		lblListHeader.setText(listHeader);
		lblListHeader.setBounds(5, 20, 240, 30);
		lblListHeader.setForeground(clrWhite);
		lblListHeader.setFont(getLabelFont());

		int i = 1;
		for (final LegenCharacterThin lct : lctList) {
			Button btnGoto = new Button(grTable, SWT.NONE);
			btnGoto.setText("GoTo");
			btnGoto.setBounds(10, 50 + (i - 1) * 40, 40, 30);
			btnGoto.addSelectionListener(new SelectionAdapter() {

				@Override
				public void widgetSelected(SelectionEvent e) {
					if (HomePageGUI.get().characterPages.containsKey(lct.getCharacterID()))
						ctfHome.setSelection(HomePageGUI.get().characterPages.get(lct.getCharacterID()).getIndex());
					else
						ControllerFunctions.get().getCharacterDetails(lct.getCharacterID());
				}
			});
			Label lblName = new Label(grTable, 0);
			lblName.setText(i + ". " + lct.getCharacterName());
			lblName.setBounds(60, 55 + (i - 1) * 40, 170, 20);
			lblName.setForeground(clrWhite);

			i++;
		}

	}

	public CharacterGUI getCharGUIPage() {
		return charGUIPage;
	}

	public void setCharGUIPage(CharacterGUI charGUIPage) {
		this.charGUIPage = charGUIPage;
	}

	public Font getHeadFont() {
		return fHeadFont;
	}

	public void setHeadFont(Font fHeadFont) {
		this.fHeadFont = fHeadFont;
	}

	public Font getLabelFont() {
		return fLabelFont;
	}

	public void setLabelFont(Font fLabelFont) {
		this.fLabelFont = fLabelFont;
	}

	public Font getButtonFont() {
		return fButtonFont;
	}

	public void setButtonFont(Font fButtonFont) {
		this.fButtonFont = fButtonFont;
	}

	/**
	 * initialize fonts
	 * 
	 * @param display
	 */
	protected void initFonts(Display display) {
		setHeadFont(new Font(display, new FontData("Fiolex Girls", 20, SWT.BOLD)));
		setLabelFont(new Font(display, new FontData("Ariel", 10, SWT.BOLD | SWT.UNDERLINE_DOUBLE)));
		setButtonFont(new Font(display, new FontData("Ariel", 10, SWT.BOLD)));

	}

}
